using System;
using System.Collections.Generic;
using System.Text;

namespace MeetFuture.MRC
{
	public partial class clsRackPosition
	{
        private const string key_Name = "RACKNAME=";
        private const string key_Bin = "BIN=";
        private const string key_Lot = "LOTID=";
        private const string key_UpdateTM = "UPDATETM=";
        private const string key_split = ",";

        private string _Name = string.Empty;
        private string _PositionID = string.Empty;
        private string _LotID = string.Empty;
        private string _UpdateTime = string.Empty;
        private RackPositionType _PosType = RackPositionType.None;
        private int _RackWidth = -1;
        private int _RackHeight = -1;
        private string _ShowId = string.Empty;
        private bool _IsError = false;

        public enum RackPositionType
        {
            None = -1,
            Output = 0,
            Input = 1,
            Empty = 2
        }
        public clsRackPosition(string RackName, string PositionID, int RackWidth, int RackHeight)
        {
            this._Name = RackName;
            this._PositionID = PositionID;
            this._LotID = string.Empty;
            this._UpdateTime = string.Empty;
            this._RackWidth = RackWidth;
            this._RackHeight = RackHeight;
            this._ShowId = GetShowID();
            this._IsError = false;
        }
        public string RackName
        {
            get { return this._Name; }
        }
        public string PositionID
        {
            get { return this._PositionID; }
        }
        public string LotID
        {
            set { this._LotID = value; }
            get { return this._LotID; }
        }
        public string ShowID
        {
            get { return this._ShowId; }
        }
        public string MoveID
        {
            get
            {
                string result = string.Empty;
                try
                {
                    int posid = Convert.ToInt32(this._PositionID);
                    if (posid > 0)
                    {
                        int level = ((posid - 1) / this._RackWidth) + 1;
                        int pos = ((posid - 1) % this._RackWidth) + 1;
                        result += this._Name + "_" + level.ToString() + "_" + pos.ToString();
                    }
                    else
                    {
                        result = string.Empty;
                    }
                }
                catch (System.Exception ex)
                {	
                }
                return result;
            }
        }
        public string UpdateTime
        {
            set { this._UpdateTime = value; }
            get { return this._UpdateTime; }
        }
        public RackPositionType PositionType
        {
            set { this._PosType = value; }
            get { return this._PosType; }
        }
        public bool IsError
        {
            set { this._IsError = value; }
            get { return this._IsError; }
        }

        private string GetShowID()
        {
            string result = string.Empty;
            try
            {
                string level_str = string.Empty;
                int level = ((Convert.ToInt32(this._PositionID) - 1) / this._RackWidth) + 1;
                int Pos = ((Convert.ToInt32(this._PositionID) - 1) % this._RackWidth) + 1;
                switch (level)
                {
                    case 1:
                    {
                        level_str = "A";
                        break;
                    }
                    case 2:
                    {
                        level_str = "B";
                        break;
                    }
                    case 3:
                    {
                        level_str = "C";
                        break;
                    }
                    case 4:
                    {
                        level_str = "D";
                        break;
                    }
                    case 5:
                    {
                        level_str = "E";
                        break;
                    }
                    case 6:
                    {
                        level_str = "F";
                        break;
                    }
                    case 7:
                    {
                        level_str = "G";
                        break;
                    }
                    case 8:
                    {
                        level_str = "H";
                        break;
                    }
                    default:
                    {
                        break;
                    }
                }
                result = level_str + Pos.ToString();
            }
            catch (System.Exception ex)
            {
            }
            return result;
        }
        public string ToObjectString()
        {
            string result = string.Empty;
            try
            {
                result += "[";
                result += key_Bin + this._PositionID + key_split;
                result += key_Lot + this._LotID + key_split;
                //result += key_UpdateTM + this._UpdateTime + key_split;
                result += "]";
            }
            catch (System.Exception ex)
            {
            }
            return result;
        }
        public override string ToString()
        {
            return this._ShowId;
        }
	}
}
